#ifndef _HRS3313_H_
#define _HRS3313_H_
#include <stdint.h>
#include <stdbool.h>

#define TIMER_READ_MODE
//#define HRS_DEBUG

#define NEW_GSEN_SCHME // New Gsen Schme after 2017-9-20

#ifdef HRS_DEBUG
#define DEBUG_PRINTF(...) SEGGER_RTT_printf(__VA_ARGS__)
#else
#define DEBUG_PRINTF(...)
#endif

typedef struct
{
    int32_t phase[3];
} hrs3313_data_t;

typedef enum
{
    MSG_ALG_NOT_OPEN = 0x01,
    MSG_NO_TOUCH = 0x02,
    MSG_PPG_LEN_TOO_SHORT = 0x03,
    MSG_HR_READY = 0x04,
    MSG_ALG_TIMEOUT = 0x05,
    MSG_SETTLE = 0x06
} hrs3313_msg_code_t;

typedef enum
{
    MSG_BP_ALG_NOT_OPEN = 0x01,
    MSG_BP_NO_TOUCH = 0x02,
    MSG_BP_PPG_LEN_TOO_SHORT = 0x03,
    MSG_BP_READY = 0x04,
    MSG_BP_ALG_TIMEOUT = 0x05,
    MSG_BP_SETTLE = 0x06
} hrs3313_bp_msg_code_t;

typedef struct
{
    hrs3313_msg_code_t alg_status;
    uint32_t data_cnt;
    uint8_t hr_result;
    uint8_t hr_result_qual; // ericy add20170111
    bool object_flg;
} hrs3313_results_t;

typedef struct
{
    hrs3313_bp_msg_code_t bp_alg_status;
    uint8_t sbp;
    uint8_t dbp;
    uint32_t data_cnt;
    uint8_t hr_result; // 20170614 ericy
    bool object_flg;
} hrs3313_bp_results_t;

//心率数据的状态（算法库给出）
typedef enum
{
    HRS_DATA_STATE_IN_CALC,  //计算中
    HRS_DATA_STATE_NOT_WEAR, //未佩戴
    HRS_DATA_STATE_READY,    //准备好
} hrs_state_t;

bool is_heart_rate_connect(void);
bool Hrs3313_chip_init(void);
void Hrs3313_alg_config(void);
bool Hrs3313_alg_open(void);
bool Hrs3313_alg_close(void);
void Hrs3313_Int_handle(void);
void Hrs3313_chip_disable(void);
extern hrs3313_results_t Hrs3313_alg_get_results(void);
bool Hrs3313_alg_send_data(int32_t new_raw_data, int32_t als_raw_data, int16_t gsen_data_x, int16_t gsen_data_y, int16_t gsen_data_z, uint16_t timer_time, int32_t red_raw_data);

bool Hrs3313_write_reg(uint8_t addr, uint8_t data);
uint8_t Hrs3313_read_reg(uint8_t addr);

bool Hrs3313_read_hrs(int32_t *hrm_data, int32_t *als_data);
bool Hrs3313_read_ps1(int32_t *infrared_data);

extern hrs3313_bp_results_t Hrs3313_alg_get_bp_results(void);
extern void Hrs3313_set_exinf(uint8_t age, uint8_t height, uint8_t weight, uint8_t gender, uint8_t ref_sbp, uint8_t ref_dbp);

/**
 * @brief 提供给hrv使用，未滤波的实际心率
 *
 * @return uint8_t
 */
extern uint8_t Hrs3313_alg_get_hr_internal(void);
hrs_state_t hr_get_data_state(void);
#endif // _HRS3313_H_
